#ifndef QRENDERTRANSFERFUNCTION1DVIEW_H
#define QRENDERTRANSFERFUNCTION1DVIEW_H

#include "glew.h"

#include <QtGui>

#include "QRenderHoverPoints.h"
#include "QRender.h"

class QRenderTransferFunction1DView : public QWidget
{
    Q_OBJECT
public:
    QRenderTransferFunction1DView(QWidget *parent);
    
    void paintEvent(QPaintEvent *e);

    
    QSize sizeHint() const { return QSize(150, 20); }
    QPolygonF points() const;
    
    QRenderHoverPoints *hoverPoints() const { return m_hoverPoints_; }
    
    float* getColorArray();
    void setRegionPixelArray(int *regionPixels);

signals:
    void colorsChanged(float *);
    
private:
    QImage backgroundImage_;
    QRenderHoverPoints *m_hoverPoints_;
    QLinearGradient m_alpha_gradient_;
    
    int regionPixelNumber_[NUMBER_INT_ENTRIES];
    float regionColor_[NUMBER_TF_ENTRIES * 4];
    int maximumPixelNumber_;
    int minValue_, maxValue_;

    
    void generateLinearGradient(QLinearGradient &linearGradient);
    void drawHistogramBackground();
    void drawColorBackground();
    
private slots:
    void updateBackground();
    void updateTransferFunction();
public slots:
	void save();
	void load();
    void slotUpdateHistogram(float* histogramData, ::size_t histogramSize);
    void slotUpdateVisHistogram(float* visHistogramData, ::size_t visHistogramSize);


private:
    ::size_t histogramSize_;
    float* histogramData_;
    //QRenderHoverPoints *m_hoverPoints_;

    //void generateLinearGradient(QLinearGradient &linearGradient);
    void drawHistogram();
    void drawColorBar();

    ::size_t visHistogramSize_;
    float* visHistogramData_;
    void drawVisHistogram();
};

#endif  // QRENDERTRANSFERFUNCTION1DVIEW_H